<template>
  <a-modal
    title="选择监听器"
    width="60%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :maskClosable="false"
    @cancel="handleCancel"
    cancelText="关闭"
    okText="确定"
    @ok="handleOk"
    style="top:20px;"
  >
    <a-spin :spinning="confirmLoading">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :scroll="{ x: true }"
        :components="components"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio'}"
        @change="handleTableChange">
      </a-table>
    </a-spin>
  </a-modal>
</template>

<script>
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'

  export default {
    name: 'ListenerSelectModal',
    mixins: [JeecgListMixin],
    data() {
      return {
        visible: false,
        confirmLoading: false,
        listenerValue: '',
        queryParam: {},
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            sorter: true,
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '名称',
            align: 'center',
            sorter: true,
            width: 250,
            dataIndex: 'listenerName',
            ellipsis: true
          },
          {
            title: '监听类型',
            align: 'center',
            sorter: true,
            width: 200,
            ellipsis: true,
            dataIndex: 'listenerType',
            customRender: function (text) {
              if (text == 1) {
                return '执行监听'
              } else if (text == 2) {
                return '任务监听'
              } else {
                return text
              }
            }
          },
          {
            title: '事件',
            align: 'center',
            sorter: true,
            width: 150,
            ellipsis: true,
            dataIndex: 'listenerEvent'
          },
          {
            title: '执行类型',
            align: 'center',
            sorter: true,
            width: 150,
            ellipsis: true,
            dataIndex: 'listenerValueType',
            customRender: function (text) {
              if (text == 'expression') {
                return '表达式'
              } else if (text == 'javaClass') {
                return 'JAVA类'
              } else if (text == 'delegateExpression') {
                return 'Spring表达式'
              } else {
                return text
              }
            }
          },
          {
            title: '执行内容',
            align: 'center',
            sorter: true,
            width: 400,
            dataIndex: 'listenerValue',
            ellipsis: true
          }],
        url: {
          list: '/process/extActListener/list',
        }
      }
    },
    methods: {
      show() {
        this.listenerValue = '';
        this.selectedRowKeys = [];
        this.selectionRows = [];
        this.visible = true
      },
      handleCancel() {
        this.visible = false
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
        this.listenerValue = selectionRows[0].listenerValue;
      },
      handleOk() {
        if(!this.listenerValue){
          this.$message.warn("请选择监听！");
          return
        }
        let selectListener = this.listenerValue
        this.$emit('selectListener', selectListener)
        this.visible = false
      }

    }
  }
</script>

<style scoped>

</style>